package cn.ctvonline.android.kaopu.base;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.KeyEvent;

import com.tendcloud.tenddata.TCAgent;

/**
 * Created by dujian on 15/12/24.
 */
public abstract class BaseActionBarActivity extends ActionBarActivity {
    protected abstract String generatePageName();

    private static String pageName;
    protected static final String TAG = BaseAppCompatActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pageName = generatePageName();
        TCAgent.onPageStart(getApplicationContext(), pageName);
    }

    @Override
    protected void onResume() {
        super.onResume();
        TCAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        TCAgent.onPause(this);
    }

    @Override
    protected void onDestroy() {
        TCAgent.onPageEnd(getApplicationContext(), pageName);
        super.onDestroy();
    }

    @Override
    public void onBackPressed() {
        finish();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            onBackPressed();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    public IncomingHandler getHandler() {
        return new IncomingHandler(this);
    }
}
